package com.yanqu.road.logic.sort;

import com.yanqu.road.entity.rank.cross.CrossUserRank;
import com.yanqu.road.utils.string.StringUtils;

import java.util.Comparator;

public class CrossUserRankSortWithParam implements Comparator<CrossUserRank> {

    @Override
    public int compare(CrossUserRank o1, CrossUserRank o2) {
        int result = o2.getValue().compareTo(o1.getValue());
        if (result != 0) {
            return result;
        }

        long param1 = 0;
        long param2 = 0;

        if (!StringUtils.isNullOrEmpty(o1.getParam())) {
            param1 = Long.valueOf(o1.getParam());
        }
        if (!StringUtils.isNullOrEmpty(o2.getParam())) {
            param2 = Long.valueOf(o2.getParam());
        }

        if (param1 != param2) {
            return Long.compare(param2, param1);
        }
        return Long.compare(o1.getLastUpdateTime(), o2.getLastUpdateTime());
    }
}
